package logic

import (
	"context"
	"user-profile/user_rpc/userrpcclient"

	"user-profile/api/internal/svc"
	"user-profile/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type FindLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewFindLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FindLogic {
	return &FindLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *FindLogic) Find(req *types.FindRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	find, err := l.svcCtx.UserRpc.Find(l.ctx, &userrpcclient.FindRequest{
		Id: int64(req.UserId),
	})
	if err != nil {
		return &types.Response{
			Code:     500,
			Message:  err.Error(),
			Database: nil,
		}, nil
	}
	return &types.Response{
		Code:     200,
		Message:  "获取成功",
		Database: find,
	}, nil
}
